﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Sisocana.Core;
using Sisocana.Core.Interfaces;
using Sisocana.Core.Models;

namespace SisocanaFronEnd.Models
{
	public class SiteProvider : ISiteProvider {
		private SiteModel _site;
        private ISiteService siteService = new SiteService();
		static SiteProvider() {
		}

		#region ISiteProvider Members

		public void Initialise(string host) {
            
            SiteModel sitio = siteService.GetSingle(s => s.subdominio.Trim() == host);
            
            if (sitio == null){
                //si no se encuentra el sitio , se usa una masterpage especial , con un mensaje especial
                _site = new SiteModel();
                _site.estado = "N";
                _site.subdominio = host;

            }
            else
            {
                _site = sitio;
                _site.dir_master = siteService.getMasterPath(sitio.id);
                _site.dir_css = siteService.getCssPath(sitio.id);
                _site = siteService.mapperCompleter(_site);
            }         
		}

		public SiteModel GetCurrentSite() {
			return _site;
		}

        public ISiteService Services
        {
            get { return siteService; }
        }


		#endregion
	}
}